package cn.xiongxf.doc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 针对于t_course表的文档映射
 * indexName：索引库
 * type：类型(表类型)
 */
@Document(indexName = "course" , type = "_doc")
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CourseDoc {

    // 课程id   PUT /index/type/id
    @Id
    private Long id;

    // 课程名，要分词
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
    private String name;

    // 等级名，不分词
    @Field(type = FieldType.Keyword)
    private String gradeName;

    // 课程类型ID
    @Field(type = FieldType.Long)
    private Long courseTypeId;

    // 课程封面
    @Field(type = FieldType.Keyword)
    private String pic;

    // 上线时间
    @Field(type = FieldType.Date)
    private Date onlineTime;

    // 老师名字，分词后可作为搜索项
    @Field(type =FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String teacherNames;

    // 免费/收费
    @Field(type = FieldType.Keyword)
    private String chargeName;

    // 价格
    @Field(type = FieldType.Double)
    private BigDecimal price;

    // 原价
    @Field(type = FieldType.Double)
    private BigDecimal priceOld;

    // 销量
    @Field(type = FieldType.Integer)
    private Integer saleCount = 0;

    // 浏览量
    @Field(type = FieldType.Integer)
    private Integer viewCount = 0;

    // 评论数
    @Field(type = FieldType.Integer)
    private Integer commentCount = 0;
}